import sympy as sp
from sympy import symbols, init_printing

# 初始化美化输出（支持LaTeX渲染）
init_printing(use_unicode=True)

# 定义符号变量
x, y, z = sp.symbols('x y z')
a, b, c = sp.symbols('a b c', real=True)  # 定义为实数
n, m = sp.symbols('n m', integer=True)    # 定义为整数

# 创建代数表达式
expr = x**2 + 2*x*y + y**2

# 表达式展开
expanded = sp.expand((x + y)**3)
print("展开后:", expanded)

# 表达式因式分解
factored = sp.factor(x**3 + 3*x**2*y + 3*x*y**2 + y**3)
print("因式分解:", factored)

# 表达式化简
complex_expr = (sp.sin(x)**2 + sp.cos(x)**2)*x**2
simplified = sp.simplify(complex_expr)
print("化简结果:", simplified)  # 输出 x²